package com.tongzhan.controller;

import com.tongzhan.base.Return;
import com.tongzhan.data.vo.*;
import com.tongzhan.service.DutiesService;
import com.tongzhan.service.StreetService;
import com.tongzhan.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system")
public class SystemController {

    @Resource
    private DutiesService dutiesService;

    @Resource
    private StreetService streetService;

    @Resource
    private UserService userService;

    /**
     * 获取权限列表接口
     *
     * @return Return
     */
    @GetMapping("/getDutiesList")
    public Return getDutiesList() {
        List<DutiesVO> dutiesVOS = dutiesService.getDutiesList();
        Map<String, Object> map = new HashMap<>();
        map.put("dutiesList", dutiesVOS);
        return new Return(map);
    }

    /**
     * 获取街道列表接口
     *
     * @return Return
     */
    @GetMapping("/getStreetList")
    public Return getStreetList() {
        List<StreetVO> streetVOS = streetService.getStreetList();
        Map<String, Object> map = new HashMap<>();
        map.put("streetList", streetVOS);
        return new Return(map);
    }

    /**
     * 根据街道编码获取场所列表接口
     *
     * @param streetCode 街道编码
     * @return Return
     */
    @PostMapping("/getSiteList")
    public Return getSiteList(String streetCode) {
        if (StringUtils.isEmpty(streetCode)) {
            return new Return(Return.MISS_PARAM, "参数缺失");
        }
        List<SiteVO> siteVOS = streetService.getSiteList(streetCode);
        Map<String, Object> map = new HashMap<>();
        map.put("siteList", siteVOS);
        return new Return(map);
    }

    /**
     * 根据宗教编码获取场所列表接口
     *
     * @param religionCode 宗教编码
     * @return Return
     */
    @PostMapping("/getSiteListByReligion")
    public Return getSiteListByReligion(String religionCode) {
        List<SiteVO> siteVOS = streetService.getSiteListByReligion(religionCode);
        Map<String, Object> map = new HashMap<>();
        map.put("siteList", siteVOS);
        return new Return(map);
    }

    /**
     * 获取所有场所列表接口
     *
     * @return Return
     */
    @GetMapping("/getSiteList")
    public Return getSiteList() {
        List<SiteVO> siteVOS = streetService.getSiteList();
        Map<String, Object> map = new HashMap<>();
        map.put("siteList", siteVOS);
        return new Return(map);
    }

    /**
     * 根据村社区编码获取场所列表接口
     *
     * @param villageCode 街道编码
     * @param dutiesCode 权限编码
     * @return Return
     */
    @PostMapping("/siteList")
    public Return siteList(String villageCode, String dutiesCode) {
        if (StringUtils.isEmpty(villageCode)) {
            return new Return(Return.MISS_PARAM, "参数缺失");
        }
        List<SiteVO> siteVOS = streetService.siteList(villageCode, dutiesCode);
        Map<String, Object> map = new HashMap<>();
        map.put("siteList", siteVOS);
        return new Return(map);
    }

    /**
     * 获取宗教团体列表接口
     *
     * @return Return
     */
    @GetMapping("/getReligionList")
    public Return getReligionList() {
        List<ReligionVO> religionVOS = streetService.getReligionList();
        Map<String, Object> map = new HashMap<>();
        map.put("religionList", religionVOS);
        return new Return(map);
    }

    /**
     * 根据街道获取村社区接口
     *
     * @param streetCode 街道编码
     * @return Return
     */
    @PostMapping("/getVillageList")
    public Return getVillageList(String streetCode) {
        if (StringUtils.isEmpty(streetCode)) {
            return new Return(Return.MISS_PARAM, "参数缺失");
        }
        List<VillageVO> villageVOS = streetService.getVillageList(streetCode);
        Map<String, Object> map = new HashMap<>();
        map.put("villageList", villageVOS);
        return new Return(map);
    }

    /**
     * 获取场所信息接口
     *
     * @param userId 用戶id
     * @return Return
     */
    @PostMapping("/getSiteInfo")
    public Return getSiteInfo(String userId) {
        if (StringUtils.isEmpty(userId)) {
            return new Return(Return.MISS_PARAM, "参数缺失");
        }
        return userService.getSiteInfo(userId);
    }
}
